package com.asion.gankapp.applacation;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.StrictMode;

import gl.com.app.DaoMaster;
import gl.com.app.DaoSession;
import gl.com.app.GankDao;
import gl.com.app.UserDao;

/**
 * Created by asion on 16-10-6.
 */

public class MyApp extends Application {
    public static Context context;
    private static SQLiteDatabase db;
    private static DaoMaster daoMaster;
    private static DaoSession daoSession;

    @Override
    public void onCreate() {
        super.onCreate();
        context = this;

        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().penaltyDeath().build());

        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().penaltyDeath().build());
    }

    public static GankDao getGankDao(){
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context,"ganks-db",null);
        db = helper.getWritableDatabase();
        daoMaster = new DaoMaster(db);
        daoSession =daoMaster.newSession();
        return daoSession.getGankDao();
    }

    public static UserDao getUserDao(){
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context,"user-db",null);
        db = helper.getWritableDatabase();
        daoMaster = new DaoMaster(db);
        daoSession =daoMaster.newSession();
        return daoSession.getUserDao();
    }
}
